<#assign title="注册">
<#include 'member_header.html'>

<!-- 获取登录信息 -->
<#assign spiteLogTag = newTag("spiteLogTag")>
<#assign flag = spiteLogTag("{'visitPage':'register.html','pageName':'注册页面','flag':'0'}")>

<#if flag==0>
	<script type="text/javascript">
		window.location.href="${ctx}/message.html?state=register";
		
	</script>
</#if>



    <!--===========layout-container================-->
    <div class="register-box" style="margin-top:20px;">
      <form class="am-form register_form" data-am-validator>
        <fieldset>
          <legend>注册用户<p class="register-info">账号使用的是学号，大小写不区分，但是仔细核对后，填入正确信息。</p></legend>

          <div class="am-form-group">
            <div class="am-g">
              <div class="am-u-md-2 am-padding-0 am-text-right">
                <label for="doc-vld-name-2" class="register-name">账号</label>
              </div>
              <div class="am-u-md-10">
                <input type="text" id="doc-vld-name-2" maxlength="10" class="student_number" name="student_number" placeholder="输入学号" required/>
              	<span class="number_msg" style="color:red;display: none;"></span>
              	<span class="number_success" style="color:green;display: none;"></span>
              </div>
            </div>
          </div>

          <div class="am-form-group">
            <div class="am-g">
              <div class="am-u-md-2 am-padding-0 am-text-right">
                <label for="doc-vld-pwd-1" class="register-pwd">密码</label>
              </div>
              <div class="am-u-md-10">
                <input type="password" id="doc-vld-pwd-1" maxlength="12" class="password" placeholder="6-12位数字、字母或符号" name="password" pattern="^[\da-zA-z]{6,12}$" required/>
              	<span class="password_msg" style="color:red;display: none;"></span>
              </div>
            </div>
          </div>

          <div class="am-form-group">
            <div class="am-g">
              <div class="am-u-md-2 am-padding-0 am-text-right">
                <label for="doc-vld-pwd-2">确认密码</label>
              </div>
              <div class="am-u-md-10">
                <input type="password" id="doc-vld-pwd-2" maxlength="12" class="repassword" placeholder="请与上面输入的值一致" name="rePassword" data-equal-to="#doc-vld-pwd-1" required/>
              	<span class="msg" style="color:red;display: none;"></span>
              </div>
            </div>
          </div>
          
          <div class="am-form-group">
            <div class="am-g">
              <div class="am-u-md-2 am-padding-0 am-text-right">
                <label for="doc-vld-name-2" class="register-name">真实姓名</label>
              </div>
              <div class="am-u-md-10">
                <input type="text" id="doc-vld-name-2" maxlength="15" class="real_name" name="real_name" placeholder="一经设置，不能更改" required/>
              	<span class="real_name_msg" style="color:red;display: none;"></span>
              </div>
            </div>
          </div>
          
          <div class="am-form-group">
            <div class="am-g">
              <div class="am-u-md-2 am-padding-0 am-text-right">
                <label for="doc-vld-name-2" class="register-name">昵称</label>
              </div>
              <div class="am-u-md-10">
                <input type="text" id="doc-vld-name-2" maxlength="10" class="nick_name" name="nick_name" required/>
              	<span class="nick_name_msg" style="color:red;display: none;"></span>
              	<span class="nick_success" style="color:green;display: none;"></span>
              </div>
            </div>
          </div>
          
          
          <div class="am-form-group">
            <div class="am-g">
              <div class="am-u-md-2 am-padding-0 am-text-right">
                <label for="doc-vld-pwd-2">验证码</label>
              </div>
              <div class="am-u-md-10">
                <input type="text" style="width:100px;float:left;" maxlength="4" id="doc-vld-pwd-2" class="checkCode" placeholder="验证码" name="checkCode" required/>
              	<img id="code_img" class="code_img" width="100px" style="float:left;margin-left:30px;" /></br></br>
              	<span class="checkCode_msg" style="color:red;display: none;"></span>
              </div>
            </div>
          </div>

          <div class="am-g">
            <div class="am-u-md-10">
              <button class="am-btn am-btn-secondary" type="button" style="outline:none;" onclick="register()">注册</button>
            </div>
          </div>
        </fieldset>
      </form>
    </div>

  </div>
  
  <!-- 弹出对话框 -->
  <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">注册</div>
    <div class="am-modal-bd">
    	<span style="color:green;">注册成功！</span>
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>




  



 
  
  
<script type="text/javascript">

$("#code_img").attr("src","${ctx}/validcode.do?vtype=admin&rmd="+new Date().getTime());

$("#code_img").click(function(){
	$(this).attr("src","${ctx}/validcode.do?vtype=admin&rmd="+new Date().getTime() );
	
});

function register(){
	var student_number=$(".student_number").val();
	var password=$(".password").val();
	var repassword=$(".repassword").val();
	var checkCode=$(".checkCode").val();
	var real_name=$(".real_name").val();
	var nick_name=$(".nick_name").val();

	//学号
	if(student_number==null || student_number==""){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号没有填写！");
		return null;
	}
	
	student_number=student_number.toUpperCase();
	var flag=student_number.indexOf("P1");
	if(flag==-1){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号填写错误！");
		return null;
	}
	var len=student_number.length;
	if(len!=10){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号填写错误！");
		return null;
	}

	//密码
	if(password==null || password==""){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码没有填写！");
		return null;
	}
	if(repassword==null || repassword==""){
		$(".msg").css("display","block");
		$(".msg").text("密码没有填写！");
		return null;
	}
	len=password.length;
	if(len<6 || len>12){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码填写错误！");
		return null;
	}
	if(password!=repassword){
		$(".msg").css("display","block");
		$(".msg").text("密码不一致！");
		return null;
	}
	
	//姓名
	if(real_name==null || real_name==""){
		$(".real_name_msg").css("display","block");
		$(".real_name_msg").text("姓名没有填写！");
		return null;
	}

	//昵称
	if(nick_name==null || nick_name==""){
		$(".nick_name_msg").css("display","block");
		$(".nick_name_msg").text("昵称没有填写！");
		return null;
	}
	
	

	//验证码
	len=checkCode.length;
	if(len!=4){
		$(".checkCode_msg").css("display","block");
		$(".checkCode_msg").text("验证码填写错误！");
		return null;
	}
	
	
	
	var options = {
		url :"${ctx}/api/member/register.do",
		type : "POST",
		dataType : 'json',
		success : function(result) {				
		 	if(result.result==1){
		 		
		 		$('#my-confirm').modal({
		 	        relatedTarget: this,
		 	        onConfirm: function(options) {
		 	        	location.href="${ctx}/index.html";
		 	        }
		 	      });
		 		
		 	}else if(result.result==0){
		 		$("body").overhang({
		 			type: "error",
		 			message: result.message
		 		});
		 	}
		},
		error : function(e) {
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
			
		}
	};
	$(".register_form").ajaxSubmit(options);
}


$(".student_number").blur(function(){
	var student_number=$(".student_number").val();

	if(student_number==null || student_number==""){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号没有填写！");
		return null;
	}
	
	student_number=student_number.toUpperCase();
	var flag=student_number.indexOf("P1");
	if(flag==-1){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号填写错误！");
		return null;
	}
	var len=student_number.length;
	if(len!=10){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号填写错误！");
		return null;
	}

	$(".number_msg").css("display","none");
	//检测学号是否可以注册
	$.ajax({
		url:"${ctx}/api/member/check-student_number.do",
		data: {'student_number':student_number},
		type:"POST",
		dataType:"json",
		success:function(result){
			if(result.result==1){
				$(".number_success").css("display","block");
				$(".number_success").text(result.message);
			}else{
				$(".number_success").css("display","none");
				$(".number_msg").css("display","block");
				$(".number_msg").text(result.message);
			}
		},
		error:function(){
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
		}
	});
	
});

$(".password").blur(function(){
	var password=$(".password").val();
	var repassword=$(".repassword").val();
	
	if(password==null || password==""){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码没有填写！");
		return null;
	}else{
		$(".password_msg").css("display","none");
	}
	if(repassword==null || repassword==""){
		$(".msg").css("display","block");
		$(".msg").text("密码没有填写！");
		return null;
	}else{
		$(".msg").css("display","none");
	}

	len=password.length;
	if(len<6 || len>12){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码填写错误！");
		return null;
	}
	if(password!=repassword){
		$(".msg").css("display","block");
		$(".msg").text("密码不一致！");
		return null;
	}

	$(".password_msg").css("display","none");
	$(".msg").css("display","none");
	
});

$(".repassword").blur(function(){
	var password=$(".password").val();
	var repassword=$(".repassword").val();
	
	if(password==null || password==""){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码没有填写！");
		return null;
	}else{
		$(".password_msg").css("display","none");
	}
	if(repassword==null || repassword==""){
		$(".msg").css("display","block");
		$(".msg").text("密码没有填写！");
		return null;
	}else{
		$(".msg").css("display","none");
	}

	len=password.length;
	if(len<6 || len>12){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码填写错误！");
		return null;
	}
	if(password!=repassword){
		$(".msg").css("display","block");
		$(".msg").text("密码不一致！");
		return null;
	}

	$(".password_msg").css("display","none");
	$(".msg").css("display","none");
	
});


$(".checkCode").blur(function(){
	var checkCode=$(".checkCode").val();

	if(checkCode==null || checkCode==""){
		$(".checkCode_msg").css("display","block");
		$(".checkCode_msg").text("验证码没有填写！");
		return null;
	}

	len=checkCode.length;
	if(len!=4){
		$(".checkCode_msg").css("display","block");
		$(".checkCode_msg").text("验证码填写错误！");
		return null;
	}

	$(".checkCode_msg").css("display","none");


	$.ajax({
		url:"${ctx}/api/checkCode/check.do",
		data: {'checkCode':checkCode},
		type:"POST",
		dataType:"json",
		success:function(result){
			if(result.result==1){
				$(".checkCode_msg").css("display","none");
			}else{
				$(".checkCode_msg").css("display","block");
				$(".checkCode_msg").text("验证码填写错误！");
			}
		},
		error:function(){
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
		}
	});

});


$(".real_name").blur(function(){
	var real_name=$(".real_name").val();

	if(real_name==null || real_name==""){
		$(".real_name_msg").css("display","block");
		$(".real_name_msg").text("姓名没有填写！");
		return null;
	}

	$(".real_name_msg").css("display","none");

});

$(".nick_name").blur(function(){
	var nick_name=$(".nick_name").val();

	if(nick_name==null || nick_name==""){
		$(".nick_name_msg").css("display","block");
		$(".nick_name_msg").text("昵称没有填写！");
		return null;
	}

	$(".nick_name_msg").css("display","none");
	//检测昵称是否可以注册
	$.ajax({
		url:"${ctx}/api/member/check-nick_name.do",
		data: {'nick_name':nick_name},
		type:"POST",
		dataType:"json",
		success:function(result){
			if(result.result==1){
				$(".nick_success").css("display","block");
				$(".nick_success").text(result.message);
			}else{
				$(".nick_success").css("display","none");
				$(".nick_name_msg").css("display","block");
				$(".nick_name_msg").text(result.message);
			}
		},
		error:function(){
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
		}
	});
});


</script>

 
 <#include 'member_footer.html'>